<template>
  <div class='m-apply_history'>
    <div style='padding-bottom: 20px;font-size: 14px;font-weight: bold;margin-bottom: 25px;border-bottom: solid 1px #e5e5e5;'>
      <span style="padding-right: 20px;">{{ phone }}</span><span>{{ short_name }}，报名详情</span>
    </div>
    <a-table :data='data' :cols='tableKeys'>
      <el-table-column align="center" label="操作" width='180' slot='ahead'>
        <template slot-scope="scope">
          <div>
            <el-button size='mini' @click='choose(scope.row.order_id)'>详情</el-button>
          </div>
        </template>
      </el-table-column>
    </a-table>
    <div class='u-pagination'>
      <!-- 分页 -->
      <pagination ref='page' @change='getData' :action='fetchData' :pageSize='20'></pagination>
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'

export default {
  name: 'm-apply_history',

  data() {
    const filterTime = (value) => {
      const d = new Date(parseInt('' + value + '000', 10))
      return window.$tools.formatDate(d)
    }
    const filterOrderStatus = window.$tools.filterStatus
    return {
      tableKeys: [
        { prop: 'order_name', label: '课程名称', minWidth: '100' },
        { prop: 'seller_name', label: '销售人员', minWidth: '100' },
        { prop: 'payment', label: '收费（元）', minWidth: '100' },
        { prop: 'create_time', label: '提交时间', minWidth: '100', filter: filterTime },
        { prop: 'status', label: '收款状态', minWidth: '100', filter: filterOrderStatus }
      ],
      data: [],
      ifRequesting: false,
      id: '',
      phone: '',
      short_name: ''
    }
  },

  mounted() {
    const { id, phone, short_name } = this.$route.query
    if (!id) {
      this.$router.push({ name: 'customer' })
      return
    }
    this.id = id
    this.phone = phone
    this.short_name = short_name
    this.$refs.page.changePage()
  },

  methods: {
    ...mapMutations(['setTabRoutes']),

    routerPush(type, args) {
      // push 到缓存里
      this.setTabRoutes({ type: 'add', obj: { ...this.getRouterInfoAccordingName(type), ...args } })
    },

    async fetchData(aPageNum, aPageSize) {
      return this.$api.orderGetBuyerOrders({
        aMerchantId: this.aFirmId,
        aBuyerId: this.id,
        aPageNum,
        aPageSize
      })
    },

    getData(data) {
      this.data = data
    },

    choose(id) {
      const query = { type: 'set', id }
      this.routerPush('courseSignUp', { query })
      this.$router.push({ name: 'courseSignUp', query })
    }
  }
}
</script>

<style lang='less'>

</style>